<?php
/**
 * Created by PhpStorm.
 * User: Duck
 * Create time: 2016/12/21 9:56
 */

namespace D\Controller;
use Common\Controller\BaseController;

class PointroleController extends BaseController{
    public function show(){
        $pages = ceil(M('points_role')->count()/4);
        $a=M('points_role')-> page(I('get.p'),4)->select();
        $c=M('points_role')->select();
        $this->assign('navs',$a);
        $this->assign('addnavs',$c);
        $this->assign('pages',$pages);
        $this->display();
    }
    public function getShow(){
        $pages = ceil(M('points_role')->count()/4);
        $res=M('points_role')
            ->page(I('get.p'),4)
            ->select();
        $this->ajaxReturn($res);
    }
    public function doDelPointrole(){
        M('points_role')->delete(I('post.ids'));
        $res = [
            'msg'=>'删除成功',
            'error'=>0
        ];
        $this->ajaxReturn($res);
    }
    public function doEditPointrole(){
       $_POST['mtime']=time();
        if(D('points_role')->create()){
            D('points_role') ->save();
            $res = [
            'msg'=>'修改成功',
            'error'=>0
        ];
        }else{
            $res = [
                'msg'=>D('points_role')->getError(),
                'error'=>1,
            ];
        }
        $this->ajaxReturn($res);
    }
    public function doAddPointrole(){
       $_POST['ctime']=time();
        if(D('points_role')->create()){
            D('points_role') ->add();
            $res = [
                'msg'=>'添加成功',
                'error'=>0
            ];
        }else{
            $res = [
                'msg'=>D('points_role')->getError(),
                'error'=>1,
            ];
        }
        $this->ajaxReturn($res);
    }
}